﻿package com.game.view.component.notification
{
	import com.dusk.util.ArrayUtil;
	import com.dusk.util.TextUtil;
	import com.game.data.constant.AttributeName;
	import com.game.data.vo.EquipmentVO;
	import com.game.view.component.ComponentBase;
	
	import flash.display.GradientType;
	import flash.display.Sprite;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	public class AttributeBox extends ComponentBase
	{
		
		public function AttributeBox(param1:EquipmentVO)
		{
			this.bg = new Sprite();
			this.info = new Sprite();
			super();
			this.attributeObj = param1;
			this.drawInfo();
			this.drawbg();
		}
		
		private var attributeObj:EquipmentVO;
		private var bg:Sprite;
		private var info:Sprite;
		private var i:uint = 0;
		private var bigw:uint = 0;
		
		private function drawInfo():void
		{
			this.addChild(this.info);
			this.info.x = 20;
			this.info.y = 10;
			var _loc1_:TextFormat = new TextFormat();
			var _loc2_:TextField = new TextField();
			_loc2_.embedFonts = true;
			_loc1_.font = TextUtil.UNIVERSAL_FONT;
			_loc1_.color = this.attributeObj.color;
			_loc1_.size = 16;
			if (this.attributeObj.getStrengthLevel() == 0)
			{
				_loc2_.text = this.attributeObj.name;
			}
			else
			{
				_loc2_.text = this.attributeObj.name + "(+" + this.attributeObj.getStrengthLevel() + ")";
			}
			_loc2_.setTextFormat(_loc1_);
			_loc2_.height = 25;
			_loc2_.width = _loc2_.textWidth + 10;
			++this.i;
			if (this.attributeObj.quality != "")
			{
				this.drawpz("品质", this.attributeObj.color, this.attributeObj.quality);
			}
			if (this.attributeObj.user != "通用")
			{
				this.drawpz("类型", 16777215, this.attributeObj.type_cn + "·" + this.attributeObj.user);
			}
			else
			{
				this.drawpz("类型", 16777215, this.attributeObj.type_cn);
			}
			if (this.attributeObj.type == "zbfb")
			{
				if (this.attributeObj.getLevel() != 0)
				{
					this.drawpz("等级", 16777215, "Lv." + this.attributeObj.getLevel());
				}
			}
			if (this.attributeObj.getGrowthRate() != 0)
			{
				this.drawpz("成长率", 16777215, this.attributeObj.getGrowthRate() + "");
			}
			if (this.attributeObj.getFiveElementString() != "")
			{
				this.drawpz("五行", 16777215, this.attributeObj.getFiveElementString());
			}
			this.drawAttribute();
			this.drawInstruction();
			this.drawValue();
			this.info.addChild(_loc2_);
		}
		
		private function drawpz(param1:String, param2:*, param3:String):void
		{
			var _loc4_:TextFormat = new TextFormat();
			var _loc5_:TextField;
			(_loc5_ = new TextField()).embedFonts = true;
			_loc4_.font = TextUtil.UNIVERSAL_FONT;
			_loc4_.color = 0;
			_loc4_.size = 16;
			_loc4_.bold = true;
			_loc5_.filters = [this.GlowEffect()];
			_loc5_.text = param1;
			_loc5_.setTextFormat(_loc4_);
			_loc5_.y = Number(this.i) * 25;
			_loc5_.height = 25;
			_loc5_.width = _loc5_.textWidth + 10;
			if (this.bigw < _loc5_.width)
			{
				this.bigw = int(_loc5_.width);
			}
			this.info.addChild(_loc5_);
			var _loc6_:Sprite;
			(_loc6_ = new Sprite()).x = _loc5_.x + _loc5_.width - 4;
			_loc6_.y = _loc5_.y + _loc5_.height - 6;
			_loc6_.graphics.lineStyle(2, 16777215);
			_loc6_.graphics.lineGradientStyle(GradientType.LINEAR, [16777215, 16777215], [1, 0], [2 * 60, 255]);
			_loc6_.graphics.moveTo(0, 0);
			_loc6_.graphics.lineTo(80, 0);
			this.info.addChild(_loc6_);
			var _loc7_:TextFormat = new TextFormat();
			var _loc8_:TextField;
			(_loc8_ = new TextField()).embedFonts = true;
			_loc7_.font = TextUtil.UNIVERSAL_FONT;
			_loc7_.color = param2;
			_loc7_.size = 16;
			_loc8_.text = "  " + param3;
			_loc8_.setTextFormat(_loc7_);
			_loc8_.x = _loc5_.x + _loc5_.width;
			_loc8_.y = _loc5_.y - 1;
			_loc8_.height = 25;
			_loc8_.width = _loc8_.textWidth + 10;
			if (this.bigw < _loc8_.width)
			{
				this.bigw = int(_loc8_.width);
			}
			this.info.addChild(_loc8_);
			++this.i;
		}
		
		private function drawAttribute():void
		{
			const noNeed:Array = ["t", "c", "ch"];
			var vo:EquipmentVO = attributeObj;
			if (ArrayUtil.contains(noNeed, vo.equipId))
			{
				return;
			}
			if (vo.getAttributeValue(AttributeName.HP) != 0)
			{
				drawSimpleAttribute("生命", vo.getAttributeValue(AttributeName.HP, false, true), vo.getAttributeValue(AttributeName.HP, false, false, true))
			}
			if (vo.getAttributeValue(AttributeName.MP) != 0)
			{
				drawSimpleAttribute("魔法", vo.getAttributeValue(AttributeName.MP, false, true), vo.getAttributeValue(AttributeName.MP, false, false, true))
			}
			if (vo.getAttributeValue(AttributeName.ATK) != 0)
			{
				drawSimpleAttribute("攻击", vo.getAttributeValue(AttributeName.ATK, false, true), vo.getAttributeValue(AttributeName.ATK, false, false, true));
			}
			if (vo.getAttributeValue(AttributeName.DEF) != 0)
			{
				drawSimpleAttribute("防御", vo.getAttributeValue(AttributeName.DEF, false, true), vo.getAttributeValue(AttributeName.DEF, false, false, true));
			}
			if (vo.getAttributeValue(AttributeName.CRIT) != 0)
			{
				drawSimpleAttribute("暴击", vo.getAttributeValue(AttributeName.CRIT, false, true), vo.getAttributeValue(AttributeName.CRIT, false, false, true));
			}
			if (vo.getAttributeValue(AttributeName.TOUGHNESS))
			{
				drawSimpleAttribute("韧性", vo.getAttributeValue(AttributeName.TOUGHNESS, false, true), vo.getAttributeValue(AttributeName.TOUGHNESS, false, false, true));
			}
			if (vo.getAttributeValue(AttributeName.HIT) != 0)
			{
				drawSimpleAttribute("命中", vo.getAttributeValue(AttributeName.HIT, false, true), vo.getAttributeValue(AttributeName.HIT, false, false, true));
			}
			if (vo.getAttributeValue(AttributeName.MISS) != 0)
			{
				drawSimpleAttribute("闪避", vo.getAttributeValue(AttributeName.MISS, false, true), vo.getAttributeValue(AttributeName.MISS, false, false, true));
			}
			if (vo.getAttributeValue(AttributeName.DE_MAGIC_DEF))
			{
				drawSimpleAttribute("破魔", vo.getAttributeValue(AttributeName.DE_MAGIC_DEF, false, true), vo.getAttributeValue(AttributeName.DE_MAGIC_DEF, false, false, true));
			}
			if (vo.getAttributeValue(AttributeName.MAGIC_DEF))
			{
				drawSimpleAttribute("魔抗", vo.getAttributeValue(AttributeName.MAGIC_DEF, false, true), vo.getAttributeValue(AttributeName.MAGIC_DEF, false, false, true));
			}
			if (vo.getAttributeValue(AttributeName.HP_HEAL) != 0)
			{
				drawSimpleAttribute("回血", vo.getAttributeValue(AttributeName.HP_HEAL, false, true), vo.getAttributeValue(AttributeName.HP_HEAL, false, false, true));
			}
			if (vo.getAttributeValue(AttributeName.MP_HEAL) != 0)
			{
				drawSimpleAttribute("回魔", vo.getAttributeValue(AttributeName.MP_HEAL, false, true), vo.getAttributeValue(AttributeName.MP_HEAL, false, false, true));
			}
			if (vo.getAttributeValue(AttributeName.BLOOD_THIRST) != 0)
			{
				drawSimpleAttribute("嗜血", vo.getAttributeValue(AttributeName.BLOOD_THIRST, false, true), vo.getAttributeValue(AttributeName.BLOOD_THIRST, false, false, true));
			}
			if (vo.getAttributeValue(AttributeName.MAGIC_THIRST) != 0)
			{
				drawSimpleAttribute("嗜魔", vo.getAttributeValue(AttributeName.MAGIC_THIRST, false, true), vo.getAttributeValue(AttributeName.MAGIC_THIRST, false, false, true));
			}
		}
		
		/**
		 * 绘制简单属性
		 * @param attribName 属性名
		 * @param base 基础属性
		 * @param strength 强化属性
		 * @param param4
		 */
		private function drawSimpleAttribute(attribName:String, base:*, strength:int = 0, param4:uint = 0):void
		{
			var tf:TextFormat;
			(tf = new TextFormat()).font = TextUtil.UNIVERSAL_FONT;
			tf.color = 0xFF9933;
			tf.size = 16;
			tf.bold = true;
			var txt:TextField;
			(txt = new TextField()).embedFonts = true;
			if (strength == 0)
			{
				txt.text = attribName + "： " + base;
			}
			else
			{
				txt.text = attribName + "： " + base + "(+" + strength + ")";
			}
			txt.setTextFormat(tf);
			txt.y = Number(this.i) * 25;
			txt.height = 25;
			txt.width = txt.textWidth + 10;
			this.info.addChild(txt);
			++this.i;
		}
		
		private function drawInstruction():void
		{
			var _loc1_:TextField = new TextField();
			_loc1_.wordWrap = true;
			_loc1_.embedFonts = true;
			_loc1_.htmlText = "<font face=\'" + TextUtil.UNIVERSAL_FONT + "\' size=\'14\' color=\'#ffffff\'>" + this.attributeObj.introduction + "</font>";
			if (this.attributeObj.isFashion())
			{
				_loc1_.htmlText += "\n\n<font face=\'" + TextUtil.UNIVERSAL_FONT + "\' size=\'14\' color=\'#ff0000\'>时装永不过期！";
			}
			_loc1_.y = Number(this.i) * 25;
			_loc1_.height = _loc1_.textHeight + 10;
			_loc1_.width = 135;
			this.info.addChild(_loc1_);
			var _loc2_:uint = Math.round(_loc1_.height / 25);
			this.i = int(this.i + _loc2_);
		}
		
		private function drawValue():void
		{
			var _loc1_:TextFormat = new TextFormat();
			_loc1_.font = TextUtil.UNIVERSAL_FONT;
			_loc1_.color = 0xFF9933;
			_loc1_.size = 14;
			var _loc2_:TextField = new TextField();
			_loc2_.embedFonts = true;
			_loc2_.text = "价值 : " + this.attributeObj.getPreciousValue() + " 灵魂";
			_loc2_.setTextFormat(_loc1_);
			_loc2_.y = Number(this.i) * 25;
			_loc2_.height = _loc2_.textHeight + 10;
			_loc2_.width = 135;
			this.info.addChild(_loc2_);
		}
		
		private function drawbg():void
		{
			this.addChild(this.bg);
			this.bg.graphics.lineStyle(1, 16777215);
			this.bg.graphics.beginFill(0, 0.7);
			this.bg.graphics.drawRoundRect(0, 0, this.info.width + 35, this.info.height + 10, 5, 5);
			this.bg.graphics.endFill();
		}
		
		private function GlowEffect():GlowFilter
		{
			return new GlowFilter(0xFFFFFF, 1, 2, 2, 3, BitmapFilterQuality.HIGH, false, false);
		}
		
		override protected function onAdded():void
		{
			if (this.getChildIndex(this.bg) > this.getChildIndex(this.info))
			{
				this.swapChildren(this.bg, this.info);
			}
		}
		
		override protected function onRemoved():void
		{
			this.removeChild(this.info);
			this.removeChild(this.bg);
		}
	}
}
